package com.zprmb.udzt;

import java.util.ArrayList;
import java.util.List;

import org.json.JSONObject;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.zprmb.udzt.adapter.Invate_Adapter;
import com.zprmb.udzt.bean.Invatejilubean;
import com.zprmb.udzt.util.Constant;
import com.zprmb.udzt.util.VolleryUtil;
/**
 * 邀请记录
 * @author shenshao
 *
 */
public class Invatejilu extends BaseActivity {
	private ImageView img_back,img_null;
	private List<Invatejilubean> list=new ArrayList<Invatejilubean>();
	private Invate_Adapter adapter;
	private ListView lv;
	private RelativeLayout rl_back;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.invate_jilu);
		 BbtApplication.getInstance().addActvity(this);
		img_back=(ImageView)findViewById(R.id.img_back);
		img_null=(ImageView)findViewById(R.id.iv_invest_null);
		lv=(ListView)findViewById(R.id.lv);
		rl_back=(RelativeLayout)findViewById(R.id.rl_back);
		rl_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		img_back.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				finish();
			}
		});
		initData();
		
	};
	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
		BbtApplication.getInstance().removeActvity(this);
	}
	private void initData() {
		// TODO Auto-generated method stub
		VolleryUtil volleryUtil=new VolleryUtil() {
			
			@Override
			public void onUpDate(JSONObject jsonObject) {
				// TODO Auto-generated method stub
				Log.e("ss", jsonObject.toString());
				if(jsonObject.optInt("success")==1){
					if (!jsonObject.optString("data").equals("null")) {
						Gson gson=new Gson();
						img_null.setVisibility(View.GONE);
						lv.setVisibility(View.VISIBLE);
						list=gson.fromJson(jsonObject.optString("data"), new TypeToken<ArrayList<Invatejilubean>>() {
							}.getType());
						adapter=new Invate_Adapter(list, Invatejilu.this);
						
						lv.setAdapter(adapter);
						
						if(list.size()<1){
							lv.setVisibility(View.GONE);
							img_null.setVisibility(View.VISIBLE);
						}else{
							lv.setVisibility(View.VISIBLE);
							img_null.setVisibility(View.GONE);
						}
//						adapter.notifyDataSetChanged();
//						setBottomAdapter(adapter, lv);
					}else{
						img_null.setVisibility(View.VISIBLE);
						lv.setVisibility(View.GONE);
					}
				}
				
			}
			
			@Override
			public void onError() {
				// TODO Auto-generated method stub
				
			}
		};
		volleryUtil.setHeaders("token", getToken());
		volleryUtil.setRequestMethod(0);
		volleryUtil.setShow(true);
		volleryUtil.execute(Invatejilu.this, Constant.URL+"/apiAccount/getRecommendInfo?pageNo=1&pageSize=100", "");
	}

}
